package com.catering.controller;
import com.catering.common.core.domain.R;
import com.catering.domain.Table;
import com.catering.service.TableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;


import java.util.List;

import static com.catering.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/table")

public class TableController {
    @Autowired
    private TableService tableService;

    //添加
    @PostMapping("/addLocation")
    @PreAuthorize("@ss.hasPermi('table:add')")
    public R addLocation(Table table){
        return R.ok(tableService.insertSelective(table));
    }
    //修改
    @PostMapping("/updateTable")
    @PreAuthorize("@ss.hasPermi('table:updateTable')")
    public R update(Table table){
        return R.ok(tableService.updateByPrimaryKeySelective(table));
    }
    //查询所有

    @GetMapping("/selAll")
    @PreAuthorize("@ss.hasPermi('table:list')")
 /*   public R selAll(){
        startPage();
       *//* System.out.println(tableService.selectAll());*//*
     return R.ok(tableService.selectAll());
    }*/
    public R selTablePage(@RequestParam(name = "pageNum",defaultValue = "1") int pageNum,@RequestParam(name = "pageSize",defaultValue = "5")int pageSize){
        System.out.println(tableService.selectAll());
        return R.ok(tableService.selTablePage(pageNum,pageSize));
    }
    //按id查询
    @GetMapping("/id")
    @PreAuthorize("@ss.hasPermi('table:list')")
    public R selById(Long id){
        return R.ok(tableService.selectByPrimaryKey(id));
    }
    //删除
    @DeleteMapping("/del")
    @PreAuthorize("@ss.hasPermi('table:remove')")
    public R delTable(Long id){
        return R.ok(tableService.deleteByPrimaryKey(id));
    }
    //模糊搜索
    @GetMapping("/like")
    @PreAuthorize("@ss.hasPermi('table:like')")
    public R selLike(String location){
        System.out.println(location);
        System.out.println(tableService.selLike(location));
        return R.ok(tableService.selLike(location));

    }

    //根据桌号修改桌台状态
    @PostMapping("/updateToOne")
    @PreAuthorize("@ss.hasPermi('table:updateTable')")
   public R updateStausIdToOneById(Long id){
        return R.ok(tableService.updateStausIdToOneById(id));
   }
    @PostMapping("/updateToTwo")
    @PreAuthorize("@ss.hasPermi('table:updateTable')")
    public R updateStausIdToTwoById(Long id){
        return R.ok(tableService.updateStausIdToTwoById(id));
    }
    @PostMapping("/updateToThree")
    @PreAuthorize("@ss.hasPermi('table:updateTable')")
    public R updateStausIdToThreeById(Long id){
        return R.ok(tableService.updateStausIdToThreeById(id));
    }





}
